import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.getAllsoledList(this);
		//获取下拉框
		this.getSplitTypeList()
		this.getSplitStatusList()
	},
	mounted() {
		
	},
	methods: {
		//导出物料拆解列表
		exportExcel(val){
			let searchFromData = this.Model.searchFromData||{}
			this.$ajax({
				method:'post',
				url:`api/materialDismantling/exportExcel`,
				data:{
					keyword:searchFromData.keyword||'',
					status:searchFromData.status||'',
					approvalTime:searchFromData.approvalTime||'',
					approvalEndTime:searchFromData.approvalEndTime||'',
				}
			}).then(res=>{
				let blob = new Blob([res.data],{type : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
				window.open(URL.createObjectURL(blob))
				// let a = document.createElement('a')
				// a.href = URL.createObjectURL(blob)
				// setTimeout(()=>{
				// 	a.click()
				// },1000)
			})
		},
		//获取列表接口
		getAllsoledList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {businessType:101};
			this.$ajax({
				method: 'post',
				url:'api/materialDismantling/list',
				data:{
					condition:params,
					pageIndex: pageIndex,
					pageSize: pageSize,
				}
			}).then((res)=>{
				that.Model.tableData = [];
				var data = res.data;
				if(data.status == 200){
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result.result;
					that.Model.tableData = result
				}else{
					that.tips(that,'warning',data.msg)
				}
			
			});
		},
		//获取拆解单类型
		getSplitTypeList(){
			this.$ajax({
				method:'get',
				url:`api/materialDismantling/dismantlingOrderType/list`
			}).then(res=>{
				let data = res.data
				if(data.status == 200 && data.result){
					for(let item of this.Model.filterOption.items){
						if(item.key=='dismantlingOrderType'){
							item.data = data.result
						}
					}
				}
			})
		},
		//获取拆解单状态
		getSplitStatusList(){
			this.$ajax({
				method:'get',
				url:`api/materialDismantling/status/list`
			}).then(res=>{
				let data = res.data
				if(data.status == 200 && data.result){
					for(let item of this.Model.filterOption.items){
						if(item.key=='status'){
							item.data = data.result
						}
					}
				}
			})
		},
		//跳转详情
		tableDetail(row) {
			this.$router.push({
				path:'goodsSplitListDetail',
				query: {
					id:row.id
				}
			});
        },
        //新建
        newPage() {
			this.$router.push({
				path:'goodsSplitListNew',
			});
        },
		//审批、作废
		operation(row,type) {
			var that = this;
			this.$confirm('是否确认'+type+'?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
                switch (type){
                    case '审批':
                    console.log('审批请求')
                        break;
                    case '作废':
                    console.log('作废请求')
                        break;
                }
			}).catch(() => {
				that.$message({
					type: 'info',
					message: '已取消'+type
				}); 
			});	
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData = val;
		},
		handleCurrentChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllsoledList(this,searchFromData,val);
		},
		handleSizeChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllsoledList(this,searchFromData,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
            let obj = val;
			if(val.approvalDate){
				obj.approvalTime = getDateString(val.approvalDate[0]);
				obj.approvalEndTime = getDateString(val.approvalDate[1]);
			}
			this.Model.searchFromData = objDeepCopy(obj);
		},
		toSearch(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllsoledList(this,searchFromData);
		},
		toClear(val) {
			this.Model.searchFromData = _.cloneDeep(this.Model.defaultSearchFromData);
		},
		toExport(val) {
			console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	}
}
export default Controller;